<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="数据库," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="世间安得双全法，不负如来不负卿  pl/sql基础基本语法12345declare	--说明用于定义变量常量等begin	--程序开始end；  :=或者into 为赋值，相当于JAVA中的= =相当于JAVA中的== ||为连字符，相当于JAVA中的+">
<meta name="keywords" content="数据库">
<meta property="og:type" content="article">
<meta property="og:title" content="pl&#x2F;sql">
<meta property="og:url" content="http://yoursite.com/2017/07/27/pl-sql/index.html">
<meta property="og:site_name" content="JokerLiang">
<meta property="og:description" content="世间安得双全法，不负如来不负卿  pl/sql基础基本语法12345declare	--说明用于定义变量常量等begin	--程序开始end；  :=或者into 为赋值，相当于JAVA中的= =相当于JAVA中的== ||为连字符，相当于JAVA中的+">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-07-27T13:25:31.853Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="pl&#x2F;sql">
<meta name="twitter:description" content="世间安得双全法，不负如来不负卿  pl/sql基础基本语法12345declare	--说明用于定义变量常量等begin	--程序开始end；  :=或者into 为赋值，相当于JAVA中的= =相当于JAVA中的== ||为连字符，相当于JAVA中的+">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/07/27/pl-sql/"/>





  <title> pl/sql | JokerLiang </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  








  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1260895995&web_id=1260895995" language="JavaScript"></script>
  </div>





  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">JokerLiang</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">永远年轻，永远热泪盈眶。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/07/27/pl-sql/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="JokerLiang">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/me.jpg">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="JokerLiang">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="JokerLiang" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                pl/sql
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-07-27T21:23:40+08:00">
                2017-07-27
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/数据库/" itemprop="url" rel="index">
                    <span itemprop="name">数据库</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <blockquote>
<p>&#x4E16;&#x95F4;&#x5B89;&#x5F97;&#x53CC;&#x5168;&#x6CD5;&#xFF0C;&#x4E0D;&#x8D1F;&#x5982;&#x6765;&#x4E0D;&#x8D1F;&#x537F;</p>
</blockquote>
<h1 id="pl-sql&#x57FA;&#x7840;"><a href="#pl-sql&#x57FA;&#x7840;" class="headerlink" title="pl/sql&#x57FA;&#x7840;"></a>pl/sql&#x57FA;&#x7840;</h1><h2 id="&#x57FA;&#x672C;&#x8BED;&#x6CD5;"><a href="#&#x57FA;&#x672C;&#x8BED;&#x6CD5;" class="headerlink" title="&#x57FA;&#x672C;&#x8BED;&#x6CD5;"></a>&#x57FA;&#x672C;&#x8BED;&#x6CD5;</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">declare</span><br><span class="line">	--&#x8BF4;&#x660E;&#x7528;&#x4E8E;&#x5B9A;&#x4E49;&#x53D8;&#x91CF;&#x5E38;&#x91CF;&#x7B49;</span><br><span class="line">begin</span><br><span class="line">	--&#x7A0B;&#x5E8F;&#x5F00;&#x59CB;</span><br><span class="line">end&#xFF1B;</span><br></pre></td></tr></table></figure>
<ul>
<li>:=&#x6216;&#x8005;into &#x4E3A;&#x8D4B;&#x503C;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;JAVA&#x4E2D;&#x7684;=</li>
<li>=&#x76F8;&#x5F53;&#x4E8E;JAVA&#x4E2D;&#x7684;==</li>
<li>||&#x4E3A;&#x8FDE;&#x5B57;&#x7B26;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;JAVA&#x4E2D;&#x7684;+<a id="more"></a>
<h2 id="&#x5F15;&#x7528;&#x5F62;&#x53D8;&#x91CF;"><a href="#&#x5F15;&#x7528;&#x5F62;&#x53D8;&#x91CF;" class="headerlink" title="&#x5F15;&#x7528;&#x5F62;&#x53D8;&#x91CF;"></a>&#x5F15;&#x7528;&#x5F62;&#x53D8;&#x91CF;</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">declare</span><br><span class="line">  --&#x5B9A;&#x4E49;&#x53D8;&#x91CF;&#x4FDD;&#x5B58;&#x59D3;&#x540D;&#x548C;&#x85AA;&#x6C34;</span><br><span class="line">  --pename varchar2(20);</span><br><span class="line">  --psal   number;</span><br><span class="line">  --&#x4E0B;&#x9762;&#x8868;&#x793A;&#x53D8;&#x91CF;&#x7C7B;&#x578B;&#x662F;emp&#x8868;&#x4E2D;ename&#x5B57;&#x6BB5;&#x7C7B;&#x578B;&#xFF0C;&#x6548;&#x679C;&#x540C;&#x4E0A;</span><br><span class="line">  pename emp.ename%type;</span><br><span class="line">  psal   emp.sal%type;</span><br><span class="line">begin</span><br><span class="line">  --&#x5F97;&#x5230;7839&#x7684;&#x59D3;&#x540D;&#x548C;&#x85AA;&#x6C34;</span><br><span class="line">  select ename,sal into pename,psal from emp where empno=7839;</span><br><span class="line"></span><br><span class="line">  --&#x6253;&#x5370;</span><br><span class="line">  dbms_output.put_line(pename||&apos;&#x7684;&#x85AA;&#x6C34;&#x662F;&apos;||psal);</span><br><span class="line">end;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h2 id="&#x8BB0;&#x5F55;&#x578B;&#x53D8;&#x91CF;"><a href="#&#x8BB0;&#x5F55;&#x578B;&#x53D8;&#x91CF;" class="headerlink" title="&#x8BB0;&#x5F55;&#x578B;&#x53D8;&#x91CF;"></a>&#x8BB0;&#x5F55;&#x578B;&#x53D8;&#x91CF;</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">--&#x8BB0;&#x5F55;&#x578B;&#x53D8;&#x91CF;: &#x67E5;&#x8BE2;&#x5E76;&#x6253;&#x5370;7839&#x7684;&#x59D3;&#x540D;&#x548C;&#x85AA;&#x6C34;</span><br><span class="line"></span><br><span class="line">declare</span><br><span class="line">  --&#x5B9A;&#x4E49;&#x8BB0;&#x5F55;&#x578B;&#x53D8;&#x91CF;&#xFF1A;&#x4EE3;&#x8868;&#x4E00;&#x884C;</span><br><span class="line">  emp_rec emp%rowtype;</span><br><span class="line">begin</span><br><span class="line">  --&#x4E0B;&#x9762;&#x4E00;&#x884C;&#x8868;&#x793A;&#xFF0C;&#x67E5;&#x51FA;emp&#x8868;&#x4E2D;empno=7839&#x7684;&#x90A3;&#x4E00;&#x884C;&#x5E76;&#x4E14;&#x8D4B;&#x503C;&#x7ED9;emp_rec&#x3002;into&#x5173;&#x952E;&#x5B57;&#x4E5F;&#x662F;&#x8D4B;&#x503C;&#x5173;&#x952E;&#x5B57;&#x3002;</span><br><span class="line">  select * into emp_rec from emp where empno=7839;</span><br><span class="line">  </span><br><span class="line">  dbms_output.put_line(emp_rec.ename||&apos;&#x7684;&#x85AA;&#x6C34;&#x662F;&apos;||emp_rec.sal);</span><br><span class="line">end;</span><br><span class="line">/</span><br></pre></td></tr></table></figure>
<h2 id="if&#x8BED;&#x6CD5;"><a href="#if&#x8BED;&#x6CD5;" class="headerlink" title="if&#x8BED;&#x6CD5;"></a>if&#x8BED;&#x6CD5;</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">--&#x63A5;&#x53D7;&#x952E;&#x76D8;&#x8F93;&#x5165;</span><br><span class="line">--&#x53D8;&#x91CF;num&#xFF1A;&#x662F;&#x4E00;&#x4E2A;&#x5730;&#x5740;&#x503C;&#xFF0C;&#x5728;&#x8BE5;&#x5730;&#x5740;&#x4E0A;&#x4FDD;&#x5B58;&#x4E86;&#x8F93;&#x5165;&#x7684;&#x503C;</span><br><span class="line">accept num prompt &apos;&#x8BF7;&#x8F93;&#x5165;&#x4E00;&#x4E2A;&#x6570;&#x5B57;&apos;;</span><br><span class="line"></span><br><span class="line">declare </span><br><span class="line">  --&#x5B9A;&#x4E49;&#x53D8;&#x91CF;&#x4FDD;&#x5B58;&#x8F93;&#x5165; &#x7684;&#x6570;&#x5B57;</span><br><span class="line">  pnum number := &amp;num;</span><br><span class="line">begin</span><br><span class="line">  if pnum = 0 then dbms_output.put_line(&apos;&#x60A8;&#x8F93;&#x5165;&#x7684;&#x662F;0&apos;);</span><br><span class="line">     elsif pnum = 1 then dbms_output.put_line(&apos;&#x60A8;&#x8F93;&#x5165;&#x7684;&#x662F;1&apos;);</span><br><span class="line">     elsif pnum = 2 then dbms_output.put_line(&apos;&#x60A8;&#x8F93;&#x5165;&#x7684;&#x662F;2&apos;);</span><br><span class="line">     else dbms_output.put_line(&apos;&#x5176;&#x4ED6;&#x6570;&#x5B57;&apos;);</span><br><span class="line">  end if;</span><br><span class="line">end;</span><br><span class="line">/</span><br></pre></td></tr></table></figure>
<h2 id="&#x5FAA;&#x73AF;"><a href="#&#x5FAA;&#x73AF;" class="headerlink" title="&#x5FAA;&#x73AF;"></a>&#x5FAA;&#x73AF;</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">-- &#x6253;&#x5370;1~10</span><br><span class="line">declare </span><br><span class="line">  -- &#x5B9A;&#x4E49;&#x53D8;&#x91CF;</span><br><span class="line">  pnum number := 1;</span><br><span class="line">begin</span><br><span class="line">  loop</span><br><span class="line">    --&#x9000;&#x51FA;&#x6761;&#x4EF6;</span><br><span class="line">    exit when pnum &gt; 10;</span><br><span class="line">    </span><br><span class="line">    --&#x6253;&#x5370;</span><br><span class="line">    dbms_output.put_line(pnum);</span><br><span class="line">    --&#x52A0;&#x4E00;</span><br><span class="line">    pnum := pnum + 1;</span><br><span class="line">  end loop;</span><br><span class="line">end;</span><br></pre></td></tr></table></figure>
<h2 id="&#x5149;&#x6807;&#xFF1A;&#x76F8;&#x5F53;&#x4E8E;JAVA&#x4E2D;&#x7684;&#x6570;&#x7EC4;"><a href="#&#x5149;&#x6807;&#xFF1A;&#x76F8;&#x5F53;&#x4E8E;JAVA&#x4E2D;&#x7684;&#x6570;&#x7EC4;" class="headerlink" title="&#x5149;&#x6807;&#xFF1A;&#x76F8;&#x5F53;&#x4E8E;JAVA&#x4E2D;&#x7684;&#x6570;&#x7EC4;"></a>&#x5149;&#x6807;&#xFF1A;&#x76F8;&#x5F53;&#x4E8E;JAVA&#x4E2D;&#x7684;&#x6570;&#x7EC4;</h2><ul>
<li>&#x5C5E;&#x6027;%isopen&#xFF0C;%rowcount(&#x5F71;&#x54CD;&#x7684;&#x884C;&#x6570;)&#xFF0C;%found&#xFF0C;%notfound<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">-- &#x67E5;&#x8BE2;&#x5E76;&#x6253;&#x5370;&#x5458;&#x5DE5;&#x7684;&#x59D3;&#x540D;&#x548C;&#x85AA;&#x6C34;</span><br><span class="line">/*</span><br><span class="line">&#x5149;&#x6807;&#x7684;&#x5C5E;&#x6027;&#xFF1A; %isopen   %rowcount(&#x5F71;&#x54CD;&#x7684;&#x884C;&#x6570;)</span><br><span class="line">             %found    %notfound</span><br><span class="line"></span><br><span class="line">*/</span><br><span class="line">declare </span><br><span class="line">   --&#x5B9A;&#x4E49;&#x5149;&#x6807;&#xFF08;&#x6E38;&#x6807;&#xFF09;</span><br><span class="line">   cursor cemp is select ename,sal from emp;</span><br><span class="line">   pename emp.ename%type;</span><br><span class="line">   psal   emp.sal%type;</span><br><span class="line">begin</span><br><span class="line">  --&#x6253;&#x5F00;</span><br><span class="line">  open cemp;</span><br><span class="line"></span><br><span class="line">  loop</span><br><span class="line">       --&#x53D6;&#x5F53;&#x524D;&#x8BB0;&#x5F55;</span><br><span class="line">       fetch cemp into pename,psal;</span><br><span class="line">       --exit when &#x6CA1;&#x6709;&#x53D6;&#x5230;&#x8BB0;&#x5F55;;</span><br><span class="line">       exit when cemp%notfound;</span><br><span class="line">       </span><br><span class="line">       dbms_output.put_line(pename||&apos;&#x7684;&#x85AA;&#x6C34;&#x662F;&apos;||psal);</span><br><span class="line">  end loop;</span><br><span class="line"></span><br><span class="line">  --&#x5173;&#x95ED;</span><br><span class="line">  close cemp;</span><br><span class="line">end;</span><br><span class="line">/</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h2 id="&#x5E26;&#x53C2;&#x6570;&#x7684;&#x5149;&#x6807;"><a href="#&#x5E26;&#x53C2;&#x6570;&#x7684;&#x5149;&#x6807;" class="headerlink" title="&#x5E26;&#x53C2;&#x6570;&#x7684;&#x5149;&#x6807;"></a>&#x5E26;&#x53C2;&#x6570;&#x7684;&#x5149;&#x6807;</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">-- &#x67E5;&#x8BE2;&#x67D0;&#x4E2A;&#x90E8;&#x95E8;&#x7684;&#x5458;&#x5DE5;&#x59D3;&#x540D;</span><br><span class="line">declare </span><br><span class="line">   --&#x5F62;&#x53C2;</span><br><span class="line">   cursor cemp(dno number) is select ename from emp where deptno=dno;</span><br><span class="line">   pename emp.ename%type;</span><br><span class="line">begin</span><br><span class="line">   --&#x5B9E;&#x53C2;</span><br><span class="line">   open cemp(20);</span><br><span class="line">   loop</span><br><span class="line">        fetch cemp into pename;</span><br><span class="line">        exit when cemp%notfound;</span><br><span class="line">        </span><br><span class="line">        dbms_output.put_line(pename);</span><br><span class="line"></span><br><span class="line">   end loop;</span><br><span class="line">   close cemp;</span><br><span class="line">end;</span><br><span class="line">/</span><br></pre></td></tr></table></figure>
<h2 id="&#x5149;&#x6807;&#x5FAA;&#x73AF;if&#x5B9E;&#x4F8B;&#xFF1A;&#x7ED9;&#x4E0D;&#x540C;&#x5458;&#x5DE5;&#x6DA8;&#x5DE5;&#x8D44;"><a href="#&#x5149;&#x6807;&#x5FAA;&#x73AF;if&#x5B9E;&#x4F8B;&#xFF1A;&#x7ED9;&#x4E0D;&#x540C;&#x5458;&#x5DE5;&#x6DA8;&#x5DE5;&#x8D44;" class="headerlink" title="&#x5149;&#x6807;&#x5FAA;&#x73AF;if&#x5B9E;&#x4F8B;&#xFF1A;&#x7ED9;&#x4E0D;&#x540C;&#x5458;&#x5DE5;&#x6DA8;&#x5DE5;&#x8D44;"></a>&#x5149;&#x6807;&#x5FAA;&#x73AF;if&#x5B9E;&#x4F8B;&#xFF1A;&#x7ED9;&#x4E0D;&#x540C;&#x5458;&#x5DE5;&#x6DA8;&#x5DE5;&#x8D44;</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">-- &#x7ED9;&#x5458;&#x5DE5;&#x6DA8;&#x5DE5;&#x8D44;&#xFF0C;&#x603B;&#x88C1;1000 &#x7ECF;&#x7406;800 &#x5176;&#x4ED6;400</span><br><span class="line">declare </span><br><span class="line">  --&#x5B9A;&#x4E49;&#x5149;&#x6807;</span><br><span class="line">  cursor cemp is select empno,job from emp;</span><br><span class="line">  pempno emp.empno%type;</span><br><span class="line">  pjob   emp.job%type;</span><br><span class="line">begin</span><br><span class="line">  rollback;  </span><br><span class="line"></span><br><span class="line">  --&#x6253;&#x5F00;&#x5149;&#x6807;</span><br><span class="line">  open cemp;  </span><br><span class="line">  loop</span><br><span class="line">       --&#x53D6;&#x4E00;&#x4E2A;&#x5458;&#x5DE5;</span><br><span class="line">       fetch cemp into pempno,pjob;</span><br><span class="line">       exit when cemp%notfound;</span><br><span class="line">       </span><br><span class="line">       --&#x5224;&#x65AD;&#x804C;&#x4F4D;</span><br><span class="line">       if pjob = &apos;PRESIDENT&apos; then update emp set sal=sal+1000 where empno=pempno;</span><br><span class="line">          elsif pjob = &apos;MANAGER&apos; then update emp set sal=sal+800 where empno=pempno;</span><br><span class="line">          else update emp set sal=sal+400 where empno=pempno;</span><br><span class="line">       end if;</span><br><span class="line"></span><br><span class="line">  end loop;</span><br><span class="line">  --&#x5173;&#x95ED;&#x5149;&#x6807;</span><br><span class="line">  close cemp;</span><br><span class="line">  </span><br><span class="line">  --&#x63D0;&#x4EA4;  ----&gt; why?: &#x4E8B;&#x52A1; ACID</span><br><span class="line">  commit;</span><br><span class="line">  </span><br><span class="line">  dbms_output.put_line(&apos;&#x5B8C;&#x6210;&apos;);</span><br><span class="line">end;</span><br><span class="line">/</span><br></pre></td></tr></table></figure>
<h2 id="&#x5F02;&#x5E38;-&#x4F8B;&#x5916;"><a href="#&#x5F02;&#x5E38;-&#x4F8B;&#x5916;" class="headerlink" title="&#x5F02;&#x5E38;(&#x4F8B;&#x5916;)"></a>&#x5F02;&#x5E38;(&#x4F8B;&#x5916;)</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">-- &#x67E5;&#x8BE2;50&#x53F7;&#x90E8;&#x95E8;&#x7684;&#x5458;&#x5DE5;</span><br><span class="line">declare </span><br><span class="line">  cursor cemp  is select ename from emp where deptno=50;</span><br><span class="line">  pename emp.ename%type;</span><br><span class="line">  </span><br><span class="line">  --&#x81EA;&#x5B9A;&#x4E49;&#x4F8B;&#x5916;</span><br><span class="line">  no_emp_found exception;</span><br><span class="line">begin</span><br><span class="line">  open cemp;</span><br><span class="line">  </span><br><span class="line">  --&#x53D6;&#x7B2C;&#x4E00;&#x6761;&#x8BB0;&#x5F55;</span><br><span class="line">  fetch cemp into pename;</span><br><span class="line">  if cemp%notfound then</span><br><span class="line">    --&#x629B;&#x51FA;&#x4F8B;&#x5916;</span><br><span class="line">    raise no_emp_found;</span><br><span class="line">  end if;</span><br><span class="line">  </span><br><span class="line">  --&#x8FDB;&#x7A0B;&#xFF1A;pmon&#x8FDB;&#x7A0B;(proccesss monitor)</span><br><span class="line">  close cemp;</span><br><span class="line"></span><br><span class="line">exception</span><br><span class="line">  when no_emp_found then dbms_output.put_line(&apos;&#x6CA1;&#x6709;&#x627E;&#x5230;&#x5458;&#x5DE5;&apos;);</span><br><span class="line">  when others then dbms_output.put_line(&apos;&#x5176;&#x4ED6;&#x4F8B;&#x5916;&apos;);</span><br><span class="line">end;</span><br><span class="line">/</span><br></pre></td></tr></table></figure>
<h1 id="pl-sql&#x8FDB;&#x9636;"><a href="#pl-sql&#x8FDB;&#x9636;" class="headerlink" title="pl/sql&#x8FDB;&#x9636;"></a>pl/sql&#x8FDB;&#x9636;</h1><h2 id="&#x5B58;&#x50A8;&#x8FC7;&#x7A0B;&#xFF08;&#x7C7B;&#x4F3C;&#x4E0E;JAVA&#x4E2D;&#x7684;&#x65B9;&#x6CD5;&#xFF09;"><a href="#&#x5B58;&#x50A8;&#x8FC7;&#x7A0B;&#xFF08;&#x7C7B;&#x4F3C;&#x4E0E;JAVA&#x4E2D;&#x7684;&#x65B9;&#x6CD5;&#xFF09;" class="headerlink" title="&#x5B58;&#x50A8;&#x8FC7;&#x7A0B;&#xFF08;&#x7C7B;&#x4F3C;&#x4E0E;JAVA&#x4E2D;&#x7684;&#x65B9;&#x6CD5;&#xFF09;"></a>&#x5B58;&#x50A8;&#x8FC7;&#x7A0B;&#xFF08;&#x7C7B;&#x4F3C;&#x4E0E;JAVA&#x4E2D;&#x7684;&#x65B9;&#x6CD5;&#xFF09;</h2><ul>
<li><p>&#x58F0;&#x660E;</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">create or replace procedure  &#x51FD;&#x6570;&#x540D;&#x5B57; (empid in number[&#x5F62;&#x5F0F;&#x53C2;&#x6570;])</span><br><span class="line">as</span><br><span class="line">   --&#x8BF4;&#x660E;&#x90E8;&#x5206;&#xFF08;&#x7528;&#x4E8E;&#x5B9A;&#x4E49;&#x53D8;&#x91CF;&#x548C;&#x5E38;&#x91CF;&#xFF09;</span><br><span class="line">begin</span><br><span class="line">   dbms_output.put_line(&apos;Hello World&apos;);</span><br><span class="line"></span><br><span class="line">end;</span><br></pre></td></tr></table></figure>
</li>
<li><p>&#x8C03;&#x7528;</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">begin</span><br><span class="line">	sayhelloworld();</span><br><span class="line">	sayhelloworld();</span><br><span class="line">   end;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h2 id="&#x5B58;&#x50A8;&#x51FD;&#x6570;&#xFF08;&#x7C7B;&#x4F3C;&#x4E0E;JAVA&#x4E2D;&#x7684;&#x65B9;&#x6CD5;&#xFF09;"><a href="#&#x5B58;&#x50A8;&#x51FD;&#x6570;&#xFF08;&#x7C7B;&#x4F3C;&#x4E0E;JAVA&#x4E2D;&#x7684;&#x65B9;&#x6CD5;&#xFF09;" class="headerlink" title="&#x5B58;&#x50A8;&#x51FD;&#x6570;&#xFF08;&#x7C7B;&#x4F3C;&#x4E0E;JAVA&#x4E2D;&#x7684;&#x65B9;&#x6CD5;&#xFF09;"></a>&#x5B58;&#x50A8;&#x51FD;&#x6570;&#xFF08;&#x7C7B;&#x4F3C;&#x4E0E;JAVA&#x4E2D;&#x7684;&#x65B9;&#x6CD5;&#xFF09;</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">create or replace function &#x51FD;&#x6570;&#x540D;&#x5B57;&#xFF08;empid out number&#xFF09;</span><br></pre></td></tr></table></figure>
<ul>
<li>&#x4E00;&#x822C; &#x53EA;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x7528;&#x5B58;&#x50A8;&#x51FD;&#x6570;&#xFF0C;&#x591A;&#x4E2A;&#x7528;out&#x8FD4;&#x56DE;&#x5B58;&#x50A8;&#x8FC7;&#x7A0B;&#x3002;</li>
</ul>
<h1 id="&#x4F7F;&#x7528;JAVA&#x8C03;&#x7528;PL-SQL"><a href="#&#x4F7F;&#x7528;JAVA&#x8C03;&#x7528;PL-SQL" class="headerlink" title="&#x4F7F;&#x7528;JAVA&#x8C03;&#x7528;PL/SQL"></a>&#x4F7F;&#x7528;JAVA&#x8C03;&#x7528;PL/SQL</h1><h2 id="JAVA&#x8C03;&#x7528;&#x50A8;&#x5B58;&#x8FC7;&#x7A0B;"><a href="#JAVA&#x8C03;&#x7528;&#x50A8;&#x5B58;&#x8FC7;&#x7A0B;" class="headerlink" title="JAVA&#x8C03;&#x7528;&#x50A8;&#x5B58;&#x8FC7;&#x7A0B;"></a>JAVA&#x8C03;&#x7528;&#x50A8;&#x5B58;&#x8FC7;&#x7A0B;</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testProcedure</span><span class="params">()</span></span>{</span><br><span class="line">		<span class="comment">//{call &lt;procedure-name&gt;[(&lt;arg1&gt;,&lt;arg2&gt;, ...)]}</span></span><br><span class="line">		String sql = <span class="string">&quot;{call queryEmpInformation(?,?,?,?)}&quot;</span>;</span><br><span class="line">		</span><br><span class="line">		Connection conn = <span class="keyword">null</span>;</span><br><span class="line">		CallableStatement call = <span class="keyword">null</span>;</span><br><span class="line">		<span class="keyword">try</span> {</span><br><span class="line">			conn = JDBCUtils.getConnection();</span><br><span class="line">			call = conn.prepareCall(sql);</span><br><span class="line">			</span><br><span class="line">			<span class="comment">//&#x5BF9;&#x4E8E;in&#x53C2;&#x6570;&#xFF0C;&#x8D4B;&#x503C;</span></span><br><span class="line">			call.setInt(<span class="number">1</span>,<span class="number">7839</span>);</span><br><span class="line">			</span><br><span class="line">			<span class="comment">//&#x5BF9;&#x4E8E;out&#x53C2;&#x6570;&#xFF0C;&#x7533;&#x660E;</span></span><br><span class="line">			call.registerOutParameter(<span class="number">2</span>, OracleTypes.VARCHAR);</span><br><span class="line">			call.registerOutParameter(<span class="number">3</span>, OracleTypes.NUMBER);</span><br><span class="line">			call.registerOutParameter(<span class="number">4</span>, OracleTypes.VARCHAR);</span><br><span class="line">			</span><br><span class="line">			<span class="comment">//&#x6267;&#x884C;</span></span><br><span class="line">			call.execute();</span><br><span class="line">			</span><br><span class="line">			<span class="comment">//&#x8F93;&#x51FA;</span></span><br><span class="line">			String name = call.getString(<span class="number">2</span>);</span><br><span class="line">			<span class="keyword">double</span> sal = call.getDouble(<span class="number">3</span>);</span><br><span class="line">			String job = call.getString(<span class="number">4</span>);</span><br><span class="line">			</span><br><span class="line">			System.out.println(name+<span class="string">&quot;\t&quot;</span>+sal+<span class="string">&quot;\t&quot;</span>+job);</span><br><span class="line">		} <span class="keyword">catch</span> (Exception e) {</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		}<span class="keyword">finally</span>{</span><br><span class="line">			JDBCUtils.release(conn, call, <span class="keyword">null</span>);</span><br><span class="line">		}</span><br><span class="line">	}</span><br></pre></td></tr></table></figure>
<h2 id="JAVA&#x8C03;&#x7528;&#x50A8;&#x5B58;&#x51FD;&#x6570;"><a href="#JAVA&#x8C03;&#x7528;&#x50A8;&#x5B58;&#x51FD;&#x6570;" class="headerlink" title="JAVA&#x8C03;&#x7528;&#x50A8;&#x5B58;&#x51FD;&#x6570;"></a>JAVA&#x8C03;&#x7528;&#x50A8;&#x5B58;&#x51FD;&#x6570;</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testFunction</span><span class="params">()</span></span>{</span><br><span class="line">		<span class="comment">//{?= call &lt;procedure-name&gt;[(&lt;arg1&gt;,&lt;arg2&gt;, ...)]}</span></span><br><span class="line">		String sql = <span class="string">&quot;{?=call queryEmpIncome(?)}&quot;</span>;</span><br><span class="line">		</span><br><span class="line">		Connection conn = <span class="keyword">null</span>;</span><br><span class="line">		CallableStatement call = <span class="keyword">null</span>;</span><br><span class="line">		<span class="keyword">try</span> {</span><br><span class="line">			conn = JDBCUtils.getConnection();</span><br><span class="line">			call = conn.prepareCall(sql);</span><br><span class="line">			</span><br><span class="line">			call.registerOutParameter(<span class="number">1</span>, OracleTypes.NUMBER);</span><br><span class="line">			call.setInt(<span class="number">2</span>, <span class="number">7839</span>);</span><br><span class="line">			</span><br><span class="line">			<span class="comment">//&#x6267;&#x884C;</span></span><br><span class="line">			call.execute();</span><br><span class="line">			</span><br><span class="line">			<span class="comment">//&#x53D6;&#x51FA;&#x5E74;&#x6536;&#x5165;</span></span><br><span class="line">			<span class="keyword">double</span> income = call.getDouble(<span class="number">1</span>);</span><br><span class="line">			</span><br><span class="line">			System.out.println(income);</span><br><span class="line">		} <span class="keyword">catch</span> (Exception e) {</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		}<span class="keyword">finally</span>{</span><br><span class="line">			JDBCUtils.release(conn, call, <span class="keyword">null</span>);</span><br><span class="line">		}		</span><br><span class="line">	}</span><br></pre></td></tr></table></figure>
<h2 id="JAVA&#x8C03;&#x7528;&#x7A0B;&#x5E8F;&#x5305;"><a href="#JAVA&#x8C03;&#x7528;&#x7A0B;&#x5E8F;&#x5305;" class="headerlink" title="JAVA&#x8C03;&#x7528;&#x7A0B;&#x5E8F;&#x5305;"></a>JAVA&#x8C03;&#x7528;&#x7A0B;&#x5E8F;&#x5305;</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Test</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testCursor</span><span class="params">()</span></span>{</span><br><span class="line">		String sql = <span class="string">&quot;{call mypackage.QUERYEMPLIST(?,?)}&quot;</span>;</span><br><span class="line">		</span><br><span class="line">		Connection conn = <span class="keyword">null</span>;</span><br><span class="line">		CallableStatement call = <span class="keyword">null</span>;</span><br><span class="line">		ResultSet rs = <span class="keyword">null</span>;</span><br><span class="line">		<span class="keyword">try</span> {</span><br><span class="line">			conn = JDBCUtils.getConnection();</span><br><span class="line">			call = conn.prepareCall(sql);</span><br><span class="line">			</span><br><span class="line">			<span class="comment">//&#x5BF9;&#x4E8E;in&#x53C2;&#x6570;&#xFF0C;&#x8D4B;&#x503C;</span></span><br><span class="line">			call.setInt(<span class="number">1</span>,<span class="number">20</span>);</span><br><span class="line">			</span><br><span class="line">			<span class="comment">//&#x5BF9;&#x4E8E;out&#x53C2;&#x6570;&#xFF0C;&#x7533;&#x660E;</span></span><br><span class="line">			call.registerOutParameter(<span class="number">2</span>, OracleTypes.CURSOR);</span><br><span class="line">			</span><br><span class="line">			<span class="comment">//&#x6267;&#x884C;</span></span><br><span class="line">			call.execute();</span><br><span class="line">			</span><br><span class="line">			<span class="comment">//&#x53D6;&#x51FA;&#x7ED3;&#x679C;</span></span><br><span class="line">			rs = ((OracleCallableStatement)call).getCursor(<span class="number">2</span>);</span><br><span class="line">			<span class="keyword">while</span>(rs.next()){</span><br><span class="line">				<span class="comment">//&#x53D6;&#x51FA;&#x4E00;&#x4E2A;&#x5458;&#x5DE5;</span></span><br><span class="line">				String name = rs.getString(<span class="string">&quot;ename&quot;</span>);</span><br><span class="line">				<span class="keyword">double</span> sal = rs.getDouble(<span class="string">&quot;sal&quot;</span>);</span><br><span class="line">				System.out.println(name+<span class="string">&quot;\t&quot;</span>+sal);</span><br><span class="line">			}</span><br><span class="line">		} <span class="keyword">catch</span> (Exception e) {</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		}<span class="keyword">finally</span>{</span><br><span class="line">			JDBCUtils.release(conn, call, rs);</span><br><span class="line">		}		</span><br><span class="line">		</span><br><span class="line">	}</span><br></pre></td></tr></table></figure>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/数据库/" rel="tag"># 数据库</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/07/27/数据库基础-基于oracle/" rel="next" title="数据库基础-基于oracle">
                <i class="fa fa-chevron-left"></i> 数据库基础-基于oracle
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/10/12/僕が死のうと思ったのは/" rel="prev" title="僕が死のうと思ったのは">
                僕が死のうと思ったのは <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/me.jpg"
               alt="JokerLiang" />
          <p class="site-author-name" itemprop="name">JokerLiang</p>
          <p class="site-description motion-element" itemprop="description">永远年轻，永远热泪盈眶。</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">61</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/LoverJoker" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.zhihu.com/people/lover-easy-7/activities" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/2292572142/profile?rightmod=1&wvr=6&mod=personinfo" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Friends
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.knight.ac.cn/" title="Knight" target="_blank">Knight</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://lzllzl.cn/" title="Zayvion" target="_blank">Zayvion</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://chen97.com/" title="Chens" target="_blank">Chens</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#pl-sql基础"><span class="nav-number">1.</span> <span class="nav-text">pl/sql基础</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#基本语法"><span class="nav-number">1.1.</span> <span class="nav-text">基本语法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#引用形变量"><span class="nav-number">1.2.</span> <span class="nav-text">引用形变量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#记录型变量"><span class="nav-number">1.3.</span> <span class="nav-text">记录型变量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#if语法"><span class="nav-number">1.4.</span> <span class="nav-text">if语法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#循环"><span class="nav-number">1.5.</span> <span class="nav-text">循环</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#光标：相当于JAVA中的数组"><span class="nav-number">1.6.</span> <span class="nav-text">光标：相当于JAVA中的数组</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#带参数的光标"><span class="nav-number">1.7.</span> <span class="nav-text">带参数的光标</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#光标循环if实例：给不同员工涨工资"><span class="nav-number">1.8.</span> <span class="nav-text">光标循环if实例：给不同员工涨工资</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#异常-例外"><span class="nav-number">1.9.</span> <span class="nav-text">异常(例外)</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#pl-sql进阶"><span class="nav-number">2.</span> <span class="nav-text">pl/sql进阶</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#存储过程（类似与JAVA中的方法）"><span class="nav-number">2.1.</span> <span class="nav-text">存储过程（类似与JAVA中的方法）</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#存储函数（类似与JAVA中的方法）"><span class="nav-number">2.2.</span> <span class="nav-text">存储函数（类似与JAVA中的方法）</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#使用JAVA调用PL-SQL"><span class="nav-number">3.</span> <span class="nav-text">使用JAVA调用PL/SQL</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#JAVA调用储存过程"><span class="nav-number">3.1.</span> <span class="nav-text">JAVA调用储存过程</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JAVA调用储存函数"><span class="nav-number">3.2.</span> <span class="nav-text">JAVA调用储存函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JAVA调用程序包"><span class="nav-number">3.3.</span> <span class="nav-text">JAVA调用程序包</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">JokerLiang</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	




  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
      search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();
    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';
      $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = $( "entry", xmlResponse ).map(function() {
            return {
              title: $( "title", this ).text(),
              content: $("content",this).text(),
              url: $( "url" , this).text()
            };
          }).get();
          var $input = document.getElementById(search_id);
          var $resultContent = document.getElementById(content_id);
          $input.addEventListener('input', function(){
            var matchcounts = 0;
            var str='<ul class=\"search-result-list\">';
            var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
            $resultContent.innerHTML = "";
            if (this.value.trim().length > 1) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var content_index = [];
                var data_title = data.title.trim().toLowerCase();
                var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                var data_url = decodeURIComponent(data.url);
                var index_title = -1;
                var index_content = -1;
                var first_occur = -1;
                // only match artiles with not empty titles and contents
                if(data_title != '') {
                  keywords.forEach(function(keyword, i) {
                    index_title = data_title.indexOf(keyword);
                    index_content = data_content.indexOf(keyword);
                    if( index_title >= 0 || index_content >= 0 ){
                      isMatch = true;
                      if (i == 0) {
                        first_occur = index_content;
                      }
                    }

                  });
                }
                // show search results
                if (isMatch) {
                  matchcounts += 1;
                  str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                  var content = data.content.trim().replace(/<[^>]+>/g,"");
                  if (first_occur >= 0) {
                    // cut out 100 characters
                    var start = first_occur - 20;
                    var end = first_occur + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if(start == 0){
                      end = 50;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    var match_content = content.substring(start, end);
                    // highlight all keywords
                    keywords.forEach(function(keyword){
                      var regS = new RegExp(keyword, "gi");
                      match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                    });

                    str += "<p class=\"search-result\">" + match_content +"...</p>"
                  }
                  str += "</li>";
                }
              })};
            str += "</ul>";
            if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
            if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
            $resultContent.innerHTML = str;
          });
          proceedsearch();
        }
      });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  

  

  


</body>
</html>
